<template>
  <yk-space size="l" dir="vertical" class="file-view">
    <TopTitle name="本地文件" :is-search="false" style="margin-bottom: 8px;">
      <template #custom>
        <yk-space align="center">
          <yk-text type="third">图片、视频、音频大小不超过20M</yk-text>
          <yk-upload :upload-url="uploadUrl" @handleSuccess="handleSuccess"></yk-upload>
        </yk-space>
      </template>
    </TopTitle>
    <subsetView :classify="2" @nowSubset="nowSelect"></subsetView>
    <filesComponent :page-size="14" :subset-id="nowSubset"></filesComponent>
  </yk-space>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import TopTitle from '@/components/bar/TopTitle.vue';
import subsetView from '@/components/subset/subsetView.vue';
import filesComponent from '@/components/files/filesComponent.vue';
import { baseUrl } from '@/utils/env';
import { useCode } from '@/hooks/code';
import { useRouter } from 'vue-router';
const { tackleCode } = useCode();
const router = useRouter();
const nowSubset = ref<number | string>(-1); // 当前分组ID

const nowSelect = (e: { id: number | string; type: string }) => {
  if (e.type === 'all') {
    nowSubset.value = -1;
  } else if (e.type === 'subset' || e.type === 'exclude') {
    nowSubset.value = e.id;
  }
}

const uploadUrl = `${baseUrl}/upload` // 上传地址
// 上传成功
const handleSuccess = (e: any) => {
  if (tackleCode(e.code)) {
    router.go(0)
  }

}

</script>

<style scoped lang="less">
.file-view {
  width: 100%;

  :deep(.yk-upload) {
    width: auto !important;
  }

  :deep(.yk-upload__file-button) {
    margin-right: 0;
  }
}
</style>
